import pyautogui
#import wxauto
import keyboard
import pyperclip

#import opencv-python   这个不需import因为是直接使用的

DEBUG =1
def debug_print(p):
    if DEBUG:
        print(p)

def click_picture(picture_path):
    button_pos =pyautogui.locateOnScreen(picture_path,confidence=0.9)#,confidence=1
    if button_pos is None:
        debug_print('没有找到按键')
        return False
    else:
        debug_print('找到按键')
        button_center=pyautogui.center(button_pos)
        return button_center

def find_button(button_pos,button_name):
    if button_pos is None:
        print('没有找到按键',button_name)
    else:
        print('找到按键',button_name)

 #有信息过来       
def ComeXinXi():
    find_msg=click_picture('./laixinxi1.png')
    if find_msg :
        pyautogui.click(find_msg)
        return True
    else:
        return False
  
#拷贝信息
def copyXinxi():


    x,y =click_picture('./img/copyflag.png')
    debug_print('ready copy')
    #debug_print(button_center)
    debug_print('copy work')
    x +=20
    y -=60
    #pyautogui.moveTo(x,y)
    pyautogui.rightClick(x,y)

        #开始复制聊天记录
        
    button_center=click_picture('./img/cp.png')
    pyautogui.click(button_center)
    text =pyperclip.paste()
    debug_print(text)
    sendXinXi(text)
        
        
        #test =pyperclip.copy()
        #print(test)
    return True
        
        
def sendXinXi(text):
    x,y =click_picture('./img/copyflag.png')
    y +=60
    pyautogui.click(x,y)
    pyautogui.hotkey('ctrl','v')    #使用热键才可以写入中文
    #pyautogui.write('?')
    pyautogui.press('enter')


#====================   start   ==========

while True:
    try:
            doSend = ComeXinXi()
            time.sleep(3)
            flag += 1
            debug_print(flag)
        except:
            pyautogui.ImageNotFoundException'''     #因为找不到，所以出现错误，只能使用try 来屏掉错误才可以继续下去
        
            



